<?php
namespace app\admin\controller\order;

use app\admin\model\order\OrderModel;
use app\admin\model\order\OrderRecordModel;
use app\admin\model\user\User;
use app\common\controller\Admin;
use app\common\annotation\NodeAnnotation;
use app\common\traits\ControllerCurd;
use think\Request;

/**
 * Class Administrator
 * @package app\admin\controller
 * @NodeAnnotation(
 *     title="订单管理",
 *     parent="default",
 *     is_menu=1,
 *     is_view=0,
 *     auth=1,
 *     icon="/material/order.png"
 * )
 */
class Index extends Admin
{
    use ControllerCurd;

    public $model;

    public function initialize()
    {
        parent::initialize();
        $this->model = new OrderModel();
    }

    /**
     * @NodeAnnotation(
     *     title="订单列表",
     *     parent="admin/order.index",
     *     is_menu=1,
     *     is_view=1,
     *     auth=1,
     *     MenuRoot="admin/order.index"
     * )
     */
    public function index()
    {
        $keywords = $this->request->param("keywords");

        $where  = [];

        if($keywords) array_push($where,["b.username|b.nickname|b.phone|b.email|a.order_number|a.order_name","eq",$keywords]);

        $orderList = $this->model->alias("a")
            ->leftjoin("cp_admin b","a.user_id=b.id")
            ->field("a.*,b.username,b.nickname,b.phone")
            ->where($where)
            ->paginate();

        $this->assign([
            "orderList" => $orderList,
            "search"   => [
                "keywords" => $keywords,
            ]
        ]);
        return $this->fetch();
    }


    /**
     * @NodeAnnotation(
     *     title="删除订单",
     *     parent="admin/order.index",
     *     is_menu=0,
     *     is_view=0,
     *     auth=1,
     *     MenuRoot="admin/order.index"
     * )
     */
    public function delorder()
    {
        $this->del('',function ($model,$data){
           // (new OrderRecordModel())->where("order_id","in",$data)->delete();
        });
        return $this->fetch();
    }


}